package com.cqc.gridviewdemo01;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.GridView;
import android.widget.ListView;

public class MainActivity extends AppCompatActivity {

    private static final String TAG = "MainActivity" ;
    private GridView gridView;
    private String[] provinces;
    private MyAdapter adapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        provinces = getResources().getStringArray(R.array.province);

        gridView = (GridView) findViewById(R.id.gridView);
        adapter = new MyAdapter(provinces);
        gridView.setAdapter(adapter);
        gridView.setSelection(0);

        gridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int i, long l) {
                view.setSelected(true);
            }
        });
    }
}
